package com.landeqing.dao.impl;

import com.landeqing.dao.importExcleDao;
import com.landeqing.model.User;
import com.landeqing.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

@Repository
public class ImportExcleDaoImpl implements importExcleDao {
    public int save(User user) {
        try {
            SqlSession sqlSession = MyBatisUtil.getSqlSession();
            int saveResult=sqlSession.insert("com.landeqing.userModel.save",user);
            sqlSession.commit();
            sqlSession.close();
            return  saveResult;
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    public User idIsExist(int id) {
        try{
            SqlSession sqlSession=MyBatisUtil.getSqlSession();
            User user=sqlSession.selectOne("com.landeqing.userModel.getById",id);
            return  user;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public int update(User user) {
        try{
            SqlSession sqlSession=MyBatisUtil.getSqlSession();
            int updateResult=sqlSession.update("com.landeqing.userModel.update",user);
            sqlSession.commit();
            sqlSession.close();
            return  updateResult;
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }
}
